package org.shopen.ai.puremvc.model.algo.containers
{
	import mx.collections.ArrayCollection;
	
	import org.shopen.ai.puremvc.model.algo.ISearchNode;

	public class BaseQueue implements IQueue
	{
		protected var data : Array = new Array();
		protected var clas : Class = ISearchNode;
		
		public function BaseQueue()
		{
		}

		public virtual function push(node:ISearchNode) : uint
		{
			return 0;
		}
		
		public virtual function pop():ISearchNode
		{
			return null;
		}
		
		public virtual function pushArray(arr:Array) : uint
		{
			var result : uint = length;
			for each (var node : ISearchNode in arr)
			{
				result = this.push(node);
			}
			return result;
		}
		
		public virtual function pushCollection(arr:ArrayCollection) : uint
		{
			var result : uint = length;
			for each (var node : ISearchNode in arr)
			{
				result = this.push(node);
			}
			return result;
		}
		
		public virtual function get length() : int
		{
			return data.length;
		}
		
		protected function getFirst() : ISearchNode
		{
			var result : ISearchNode = null;
			if (length > 0)
			{
				result = data[0];
			}
			return result;
		}
		
		protected function popFirst() : ISearchNode
		{
			var result : ISearchNode = null;
			if (length > 0)
			{
				result = data.shift();
			}
			return result;
		}
		
		protected function pushStart(value : ISearchNode) : uint
		{
			var result : uint = data.unshift(value);
			return result;
		}
		
		protected function pushEnd(value : ISearchNode) : uint
		{
			var result : uint = data.push(value);
			return result;
		}
		
		protected function getLast() : ISearchNode
		{
			var result : ISearchNode = null;
			if (length > 0)
			{
				result = data[length - 1];
			}
			return result;
		}
		
		protected function popLast() : ISearchNode
		{
			var result : ISearchNode = null;
			if (length > 0)
			{
				result = data.pop();
			}
			return result;
		}
		
	}
}